import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import store from '../store'

Vue.use(VueRouter)

const routes = [
    {
      path: '/',
      redirect:"/login"
    },
    {
      path: '/login',
      component: Login
    },
    { 
      path: '/home',
      component: () => import('../views/Home.vue'),
      children:[
        {
          path:"/bizList",
          component: () => import('../views/business/bizList.vue')
        },
        {
          path:"/bizVerify",
          component: () => import('../views/business/bizVerify.vue')
        },
        {
          path:"/inputOrder",
          component: () => import('../views/order/inputOrder.vue')
        },
        {
          path:"/orderList",
          component: () => import('../views/order/orderList.vue')
        },
        {
          path:"/staffOrder",
          component: () => import('../views/order/staffOrder.vue')
        },
        {
          path:"/userManage",
          component: () => import('../views/user/UserManage.vue')
        },
        {
          path:"/staffList",
          component:() => import('../views/staff/staffList.vue')
        },
        {
          path:"/driverOrder",
          component: () => import('../views/order/driverOrder.vue')
        },
        {
          path:"/driverList",
          component: () => import('../views/order/driverlist.vue')
        },
        {
          path:"/stationList",
          component: () => import('../views/order/stationList.vue')
        },
      ]
    },
  ]

const router = new VueRouter({
  // mode: 'history',
  base: '/cjjconsole/',
  routes
}) 

router.beforeEach(function(to,from,next){
  if(to.path!=="/login"&&!store.state.LoginModule.token){
    next("/login");
  }
  next();
})

export default router
